define(['app'], function(app) {
    'use strict';
    //实例化方法
    var factory = function (Http) {
        /**
         * 一键切换数据获取方式
         * @param {Object} result
         */
        function get_data_detail(result) {
            if (!false) {
                result = '{"success":true,"msg":"","result":{"act_id":"001","name":"促销","abstract":"哦嚯嚯嚯，你是猴子派来的救兵吗","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","apply_end_time":"2017/01/31 09:00:00","brand_id":"001","brand_name":"博世","cat_type_id":"001","cat_type_name":"电动工具","group_id":"12345897","paper":{"paper_id":"001","questions":[{"id":"1","question":"问题1","answer":[{"id":"001","choose_no":"A","data":"答案1"},{"id":"002","choose_no":"A","data":"答案1"}]},{"id":"2","question":"问题2","answer":[{"id":"001","choose_no":"A","data":"答案1"},{"id":"002","choose_no":"A","data":"答案1"}]}]}},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
               return JSON.parse(result);
            }
            else {
                return result;
            }
        }
        
        function get_data_goodslist(result) {
            if (!false) {
                result = '{"success": true,"msg": "","result": {"act_id": "001","goods": {"id": "001","name": "一字螺丝刀","image": "001.jpg","price": 10}},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
               return JSON.parse(result);
            }
            else {
                return result;
            }
        }
        
        //返回信息
        return {
            //详情
            detail: function (act_id, callback) {
                Http.post({
                    method: 'goods.giving.detail', 
                    act_id: act_id
                }, function (result) {
                    //请求成功
                    if (callback) {
                        callback(get_data_detail(result).result);
                    }
                }, function (e) {
                    //请求异常
                }, function () {
                    //请求完成，一般不做什么事情
                });
            }, 
            //商品详情
            goodslist: function (act_id, callback) {
                Http.post({
                    method: 'goods.giving.goodslist', 
                    act_id: act_id
                }, function (result) {
                    //请求成功
                    if (callback) {
                        callback(get_data_goodslist(result).result);
                    }
                }, function (e) {
                    //请求异常
                }, function () {
                    //请求完成，一般不做什么事情
                });
            }, 
            //提交问卷--"立即申请"按钮
            apply: function (act_id, paper_id, answer, callback) {
                Http.post({
                    method: 'goods.giving.apply', 
                    paper_id:paper_id,
                    answer:answer
                }, function (result) {
                	//请求成功
                	if (callback) 
                        callback(result);
                }, function (e) {
                    //请求异常
                }, function () {
                    //请求完成，一般不做什么事情
                });
            }
        };
    }
    factory.$inject = ['Http'];
    return app.registerService("Newproductpost_give", factory);
});